<template>
  <common-search :col-layout="{xxl: 6, xl:8, lg: 8, md: 12, sm: 24, xs: 24}" v-model="query" :formItems="formItems" @search="search" @reset="reset"></common-search>
  <a-button type="primary" v-modulePerm="['foShan:export']" @click="exports" :loading="exportLoading">导出</a-button>
  <common-table
      :columns="columns"
      :dataSource="dataList"
      v-model:loading="loading"
      v-model:localPagination="page"
      @paginationChange="onPageChange"
      :scroll="{ x: 'max-content'}"
  >
  </common-table>

</template>
<script>
export default {
  name:"foshan-index"
}
</script>
<script setup>
import CommonSearch from "@/components/commonSearch/index.vue";
import CommonTable from "@/components/commonTable/index.vue";
import {useSearchTable} from "@/hooks/table/useSearchTable";
import { ref, onMounted } from "vue";
import {message} from "ant-design-vue";
import {postFile} from "@utils/service/index.js";
import {getManyDictItems} from "@/api/system/dict.js";
import {foShanTaskPage} from "@/api/foshan/index.js";
const columns = [
  {
    title: "站点",
    dataIndex: "site",
    key: "site",
    align: 'center',
  },
  {
    title: "销售平台",
    dataIndex: "platform",
    key: "platform",
    align: 'center'
  },
  {
    title: '平台订单',
    dataIndex: 'orderId',
    key: 'orderId',
    align: 'center'
  },
  {
    title: '易仓订单',
    dataIndex: 'saleOrderCode',
    key: 'saleOrderCode',
    align: 'center'
  },
  {
    title: '当前仓库',
    dataIndex: 'eccangCurWarehouse',
    key: 'eccangCurWarehouse',
    align: 'center'
  },
  {
    title: '状态',
    dataIndex: 'orderStatus_dictText',
    key: 'orderStatus_dictText',
    align: 'center'
  },
  {
    title: '下单日期',
    dataIndex: 'orderCreateTime',
    key: 'orderCreateTime',
    align: 'center'
  },
  {
    title: '仓库SKU',
    key: 'warehouseSku',
    dataIndex: 'warehouseSku',
    align: "center"
  },
  {
    title: '数量',
    key: 'qty',
    dataIndex: 'qty',
    align: "center"
  },
  {
    title: '发货仓库',
    key: 'expectWarehouse',
    dataIndex: 'expectWarehouse',
    align: "center"
  },
  {
    title: '需要拆单',
    key: 'isSplit',
    dataIndex: 'isSplit_dictText',
    align: "center"
  },
];
const exportLoading = ref(false);
const { dataList, query, loading, page, search, reset, onPageChange } = useSearchTable({
  searchAPI: foShanTaskPage,
  queryFactory: () => ({
  }),
});
const formItems = ref([
  {
    label:'易仓订单',
    type:'input',
    field:'saleOrderCode',
  },
  {
    label:'订单状态',
    type:'select',
    field:'orderStatus',
    options:[]
  },
  {
    label:'是否需要拆单',
    type:'select',
    field:'isSplit',
    options:[
      {
        label:'全部',
        value:''
      },
      {
        label:'是',
        value:'Y'
      },
      {
        label:'否',
        value:'N'
      }
    ]
  },
  {
    label:'仓库sku',
    type:'input',
    field:'warehouseSku',
  },
])
const exports = async () => {
  try{
    exportLoading.value = true;
    let obj = query.value
    // 获取当天日期
    const date = new Date();
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const res = await postFile('/foshan/task/export','post',obj,`佛山直发-${year}${month}${day}.xlsx`)
    message.success('导出成功')
  }catch (e) {
    message.error(e);
  }finally {
    exportLoading.value = false;
  }
}
const init = async () => {
  try{
    const res = await getManyDictItems({
      dictCodeList:"foshan_task_order_status"
    })
    formItems.value[1].options = res.result.foshan_task_order_status

  }catch (e){
    console.log(e)
  }
}

onMounted(() => {
  init()
})
</script>
<style scoped>

</style>
